    <?php
    function display_login_box()
    {
       echo 'Please log in:<br /><form method="POST" action="/login.php">
       <p>Username: <input type="text" name="username" size="40"><br />
       Password: <input type="password" name="password" size="40"><br />
       Remember Me?: <input type="checkbox" name="autologin"><br />
       <input type="submit" value="Submit" name="login"></p>
       <input type="hidden" name="redirect" value="'.$current_page.'">
       </form>';
    }
    define('IN_PHPBB', true);
    $phpbb_root_path = './forum/';
    $phpEx = substr(strrchr(__FILE__, '.'), 1);
    include($phpbb_root_path . 'common.' . $phpEx);

    // Start session management
    $user->session_begin();
    $auth->acl($user->data);
    $user->setup();
    if($user->data['is_registered'])
     {
      //User is already logged in
      echo "You're already logged in!"; 
     }
     else
     {
      $username = request_var('username', '', true);
      $password = request_var('password', '', true);
      $autologin = (!empty($_POST['autologin'])) ? true : false;

      $result = $auth->login($username, $password, $autologin);

      if ($result['status'] == LOGIN_SUCCESS)
      {
        //User was successfully logged in
        //Redirect to the page they were viewing
        $redirect = request_var('redirect', "index.php");

        // append/replace SID
        $redirect = reapply_sid($redirect);

        meta_refresh(0, $redirect);
       }
       else
       {
        display_login_box();
       }

     }
    ?>
